#!/usr/bin/env python
# -*- coding: utf-8 -*-


#[year, update, (social_I, social), (time, people), complaint, (video, load), contact]
w = [4/28., 5/28., 2/7., 1/7., 1/7., 1/28., 2/28.]
k = [1., 1., 1./100, 1./100, -1./100, 1/10., 1.]


result_dict = {}
def calculate(param_file, output_file):
    temp = []
    for i in range(0, 7):
        temp.append(w[i] * k[i])
    result = []
    opf = open(output_file, 'w+')
    with open(param_file, 'r+') as f:
        for line in f:
            if '#' not in line:
                arr = line.strip().split('\t')
                param = arr[1:]
                opf.write('%s\t%10.10f\n' % (arr[0], calculate_line(temp, param)))
                result.append(calculate_line(temp, param))
    print 'max:%s, min:%s' % (str(max(result)), str(min(result)))    
def calculate_line(temp, arr):
    #[year, update, social, (time, people), complaint, (video, load), contact]  
    result = temp[0] * 1/(1+float(arr[0]))          \
           + temp[1] * 1/(1+float(arr[1]))              \
           + temp[2] * float(arr[2]) * float(arr[3])\
           + temp[3] * float(arr[4]) / float(arr[5])\
           + temp[4] * float(arr[6])                \
           + temp[5] * float(arr[7]) / float(arr[8])\
           + temp[6] * int(arr[9])
    return result
               
def main():
    param_file = '/home/ivy/git/BD_py/PageRank_py/project/resource/param.txt'
    output_file = '/home/ivy/git/BD_py/PageRank_py/project/resource/param_cal.txt'  
    calculate(param_file, output_file)
    
if __name__ == '__main__':
    main()
    